package com.jkai.springbootdemo1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class UserService {
	@Autowired
	private  LoadBalancerClient balancerClient;
	
	public String getUser() {
		ServiceInstance si = this.balancerClient.choose("provider");
		StringBuffer sbf = new StringBuffer();
		sbf.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/login");
		RestTemplate rt = new RestTemplate();
		return rt.getForEntity(sbf.toString(), String.class).getBody();
	}
}
